package com.sunda.spmsorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sunda.spmsorder.entity.MaterialApplicationDtl;
import com.sunda.spmsorder.mapper.MaterialApplicationDtlMapper;
import com.sunda.spmsorder.service.IMaterialApplicationDtlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 物料申请单明细表 服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-05-21
 */
@Service
public class MaterialApplicationDtlServiceImpl extends ServiceImpl<MaterialApplicationDtlMapper, MaterialApplicationDtl> implements IMaterialApplicationDtlService {

    @Autowired
    MaterialApplicationDtlMapper materialApplicationDtlMapper;

    @Override
    public int insertMaterialApplicationDtl(MaterialApplicationDtl materialApplicationDtl) {
        return materialApplicationDtlMapper.insert(materialApplicationDtl);
    }

    @Override
    public int deleteMaterialApplicationDtls(String applicationUuid) {
        return this.baseMapper.delete(new QueryWrapper<MaterialApplicationDtl>().eq("APPLICATION_UUID", applicationUuid));
    }

    @Override
    public List<MaterialApplicationDtl> getMaterialApplicationDtlList(String applicationUuid) {
        return this.baseMapper.selectList(new QueryWrapper<MaterialApplicationDtl>().eq("APPLICATION_UUID", applicationUuid).orderByAsc("APPLICATION_ITEM"));
    }

    @Override
    public List<MaterialApplicationDtl> getMatBySpmsStatus(){
        return this.baseMapper.findMatBySpmsStatus();
    }

    @Override
    public List<Map<String,Object>> getMatBySpms(Page<Map<String, Object>> pages){
        return this.baseMapper.findMatBySpms(pages);
    }

    @Override
    public List<Map<String,Object>> getExcelMap(String applicationId, String applicationItem, String cpx, String applicationUuid, String werks, String specs, String materialEnDesc, String userId, String name, String materialNo){
        return this.baseMapper.findExcelMat(applicationId, applicationItem, cpx, applicationUuid, werks, specs, materialEnDesc, userId, name, materialNo);
    }

    @Override
    public List<Map<String,Object>> getMatBySpmsNParam(Page<Map<String, Object>> pages,String applicationId, String applicationItem, String cpx, String applicationUuid, String werks, String specs, String materialEnDesc, String userId, String name, String materialNo, String beginDate, String endDate){
        return this.baseMapper.findMatBySpmsNParam(pages,applicationId, applicationItem, cpx, applicationUuid, werks, specs, materialEnDesc, userId, name, materialNo, beginDate, endDate);
    }

    @Override
    public int updateMaterialNoByList(String materialNo, String applicationUuid, String applicationItem){
        try{
            int i = this.baseMapper.updateMatByItem(materialNo, applicationUuid, applicationItem);
            return i;
        }catch (Exception e){
            System.out.println(e.getMessage());
            return 0;
        }
    }
}
